<form method="post" action="{ADMINSCRIPT}?action=plugins&operation=config&do='.$pluginid.'&identifier=erling_filedset&pmod=admin_config">
<input type="hidden" name="formhash" value="{FORMHASH}" />
<table class="tb tb2">
<tr><th>配置名称</th><th>配置值</th><th>配置说明</th></tr>

<!--{loop $configs $config}-->
<!--{if !in_array($config['key'], ['position_float_value', 'position_float_color', 'position_float_bgcolor'])}-->
<tr>
    <td>{$config['name']}</td>
    <td>
    <!--{if $config['key'] == 'allowed_groups'}-->
        <!--{eval 
            $allowed_groups = dunserialize($config['value']);
        }-->
        <select name="config[{$config['key']}][]" multiple="multiple" style="height:200px;width:200px;">
            <option value="clear" onclick="this.parentNode.querySelectorAll('option').forEach(opt => opt.selected = false); this.selected = true">-- 清空选择 --</option>
            
            <!-- 会员用户组 -->
            <optgroup label="会员用户组">
                <!--{loop $member_groups $group}-->
                <option value="{$group['groupid']}" <!--{if is_array($allowed_groups) && in_array($group['groupid'], $allowed_groups)}-->selected<!--{/if}-->>{$group['grouptitle']}</option>
                <!--{/loop}-->
            </optgroup>
            
            <!-- 管理用户组 -->
            <optgroup label="系统用户组">
                <!--{loop $system_groups $group}-->
                <option value="{$group['groupid']}" <!--{if is_array($allowed_groups) && in_array($group['groupid'], $allowed_groups)}-->selected<!--{/if}-->>{$group['grouptitle']}</option>
                <!--{/loop}-->
            </optgroup>
            
            <!-- 自定义用户组 -->
            <optgroup label="自定义用户组">
                <!--{loop $special_groups $group}-->
                <option value="{$group['groupid']}" <!--{if is_array($allowed_groups) && in_array($group['groupid'], $allowed_groups)}-->selected<!--{/if}-->>{$group['grouptitle']}</option>
                <!--{/loop}-->
            </optgroup>
        </select>
        <script>
        document.currentScript.parentNode.querySelector('select').addEventListener('change', function(e) {
            if(e.target.querySelector('option[value="clear"]:checked')) {
                e.target.querySelectorAll('option').forEach(opt => opt.selected = false);
            }
        });
        </script>
    <!--{elseif $config['key'] == 'position'}-->
        <select name="config[{$config['key']}]">
        <!--{loop $positions $value $label}-->
            <option value="{$value}" <!--{if $config['value'] == $value}-->selected<!--{/if}-->>{$label}</option>
        <!--{/loop}-->
        </select>
    <!--{elseif $config['key'] == 'mobile_position'}-->
        <select name="config[{$config['key']}]">
        <!--{loop $mobile_positions $value $label}-->
            <option value="{$value}" <!--{if $config['value'] == $value}-->selected<!--{/if}-->>{$label}</option>
        <!--{/loop}-->
        </select>
    <!--{elseif $config['key'] == 'path_before'}-->
        <!--{eval 
            $path_values = json_decode($config['value'], true);
            $path_values = is_array($path_values) ? $path_values : [];
            $a = '列表';
        }-->
        <div id="path_before_container">
            <!--{loop $path_values $index $value}-->
            <div>
                <!--{eval echo $a; }-->地址：<input type="text" name="config[{$config['key']}][]" value="{$value}" /> /20cms/文件名.txt
                <!-- <button type="button" onclick="this.parentNode.remove()">删除</button> -->
                <!--{eval $a = '备用'; }-->
            </div>
            <!--{/loop}-->
        </div>
        <!-- <button type="button" onclick="addPathInput()">添加路径</button> -->
        <script>
        function addPathInput() {
            const container = document.getElementById('path_before_container');
            const div = document.createElement('div');
            div.innerHTML = `
                列表地址：<input type="text" name="config[path_before][]" value="" />
                备用地址：<button type="button" onclick="this.parentNode.remove()">删除</button>
            `;
            container.appendChild(div);
        }
        </script>
    <!--{else}-->
        <input type="text" name="config[{$config['key']}]" value="{$config['value']}" />
    <!--{/if}-->
    </td>
    <td>{$config['desc']}</td>
</tr>
<!--{/if}-->
<!--{/loop}-->

</table>
<input type="submit" class="btn" name="configsubmit" value="提交保存" />
</form>